<template>
	<view v-if="shenheStatus == 0 " class="cash">
		<!-- 提现方式 -->
		<view @click="showPopup = true" class="way flex-y-center flex-x-sb">
			<view>{{ $t("mdAdmin.withdrawMethods") }}{{text}}</view>
			<view v-if="select_type == 'wechat'" class="flex-y-center">
				<text class="iconfont icon-wechat"
					style="color: #2fc445; font-size: 36rpx; margin: 0 22rpx 0 6rpx"></text>
				<text>{{ $t("shop.wx") }}({{ cardData("wechat").account }})</text>
				<text class="iconfont icon-arrow-right" style="font-size: 22rpx"></text>
			</view>

			<view v-else-if="select_type == 'alipay'" class="flex-y-center">
				<text class="iconfont icon-zhifubao1" style="color: #2777fe; font-size: 44rpx"></text>
				<text>{{ $t("shop.alipay") }}({{ cardData("alipay").account }})</text>
				<text class="iconfont icon-arrow-right" style="font-size: 22rpx"></text>
			</view>

			<view v-else-if="select_type == 'bank_card'" class="flex-y-center">
				<text class="iconfont icon-yinhangka1" style="color: #3fbafe; font-size: 44rpx"></text>
				<text>{{ cardData("bank_card").bank }}({{
            cardData("bank_card").account | toString4
          }})</text>
				<text class="iconfont icon-arrow-right" style="font-size: 22rpx"></text>
			</view>
			<view v-else-if="select_type == 'money'" class="flex-y-center">
				<text class="iconfont icon-consumption-fill" style="color: #f1a74c; font-size: 44rpx"></text>
				<text>{{ $t("shop.money") }}</text>
				<text class="iconfont icon-arrow-right" style="font-size: 22rpx"></text>
			</view>

			<!-- <view v-else-if="select_type == 3" class="flex-y-center">
        <text
          class="iconfont icon-consumption-fill"
          style="color: #fbc210"
        ></text>
        <text>微信零钱</text>
        <text class="iconfont icon-arrow-right"></text>
      </view> -->

			<view v-else class="flex-y-center">
				<text class="" style=""></text>
				<text>{{ $t("mdAdmin.chooseMethods") }}</text>
				<text class="iconfont icon-arrow-right" style="font-size: 22rpx"></text>
			</view>
		</view>

		<!-- 提现输入框 -->
		<view class="input-box">
			<view class="input-title">{{ $t("mdAdmin.withMoney") }}</view>
			<view class="input">
				<view>￥</view>
				<view>
					<u-input v-model="inputNum" placeholder=" " type="digit"></u-input>
				</view>
			</view>
		</view>

		<!-- 全部提现 -->
		<view class="all-withdrawal">
			<template v-if="witData.service_content">{{ witData.service_content }},</template>
			<!--  <template v-if="witData.cash_max_day >= 0"
        >{{ $t("shop.mostWithdrow") }}{{ witData.cash_max_day }}，</template
      > -->
			{{ $t("mdAdmin.canWith") }}{{ witData.price
      }}{{ $t("mdAdmin.canWith1") }}，<text @click="inputNum = witData.price"
				style="color: #f0250e; font-weight: 600">{{ $t("shop.allWithdraw") }}</text>
		</view>

		<!-- 提交button -->
		<view @click="submit" class="btn flex-y-center flex-x-center">{{
      $t("mdAdmin.quickWith")
    }}</view>

		<!-- 提现方式选择框 -->
		<u-popup v-model="showPopup" mode="center" border-radius="24">
			<view class="popup-box">
				<view class="title"> {{ $t("mdAdmin.chooseMethods") }} </view>
				<view v-for="(item, index) in cardList" :key="index" @click="switchPayIndex(item.type,item,index)"
					class="popup-item flex-y-center flex-x-sb">
					<view v-if="item.type == 'wechat'" class="flex-y-center">
						<text class="iconfont icon-wechat"
							style="color: #2fc445; font-size: 36rpx; margin: 0 22rpx 0 6rpx"></text>
						{{ $t("shop.wx") }}
					</view>
					<view v-else-if="item.type == 'alipay'" class="flex-y-center">
						<text class="iconfont icon-zhifubao1" style="color: #2777fe"></text>
						{{ $t("shop.alipay") }}
					</view>
					<view v-else-if="item.type == 'bank_card'" class="flex-y-center">
						<text class="iconfont icon-yinhangka1" style="color: #3fbafe"></text>
						{{ $t("shop.card") }}
					</view>
					<view v-else-if="item.type == 'money'" class="flex-y-center">
						<text class="iconfont icon-consumption-fill" style="color: #f1a74c"></text>
						{{ $t("shop.money") }}
					</view>
					<view>
						<text v-show="select_type == item.type" class="iconfont icon-seleted"
							style="color: #f0250e"></text>
					</view>
				</view>

				<view @click="switchPayIndex(-1)" class="popup-item flex-y-center">
					<text class="iconfont icon-CurrencyConverter-fill" style="color: #34b6ff"></text>
					{{ $t("mdAdmin.addMethod") }}
				</view>
			</view>
		</u-popup>
	</view>
	<Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
	import {
		getPrice,
		cashApply
	} from "@/api/recharge";
	import Shenhe from "@/components/shenhe/shenhe";
	export default {
		components: {
			Shenhe
		},
		data() {
			return {
				inputNum: "", //输入提现金额
				showPopup: false, //popup弹框开关
				witData: {}, //提现所有数据
				cardList: [], //钱包列表
				select_type: -1, //选中提现方式索引
				type: "", // balance余额提现申请
				is_share_recharge: 1,
				mchObj: {},
				nextType: '',
				text: '',
				types: '',
				new:null,
			};
		},
		onLoad(t) {
			this.type = t.type || "";
		},
		onShow() {
			// 获取个人数据
			this.getCashInfo();
		},
		methods: {
			// 获取提现数据
			async getCashInfo() {
				let money = await this.$allrequest.teamCenter.getMsg()
				this.witData.service_content = `提现需加收${money.data.conf.cash_rate}%手续费`
				this.nextType = money.data.conf.cash_type
			
				let user = await this.$allrequest.mch_store.userMsg()
				this.witData.price = user.data.user.price
				let s1 = JSON.parse(user.data.saasUser.withdraw_method)
				this.cardList = s1;
				console.log('入驻商获取用户信息：用户信息', this.cardList)
			},
			// 切换提现方式
			switchPayIndex(type, item,index) {
				this.mchObj = item
				this.types = this.nextType.some(item => item == index);
				console.log('this.nextType',this.nextType,index,this.types)
				if (!this.types && type!= -1) {
                    return this.$utils.toast('不支持此提现方式')
				}
			
				if (type != -1) {
					this.select_type = type;
					this.new=index
					this.showPopup = false;
				} else {
					this.$utils.toUrl(
						`/user/share/pay-list?is_share_recharge=${this.is_share_recharge}`,
						"navigate"
					);
					this.showPopup = false;
				}
			},
			submit() {
				this.$u.throttle(async () => {
					if (this.select_type == -1)
						return this.$utils.toast(this.$t("mdAdmin.chooseMethods"));
					var reg1 = /^[0-9]+(\.[0-9]{0,2})?$/;
					if (!reg1.test(this.inputNum))
						return this.$utils.toast(this.$t("mdAdmin.confirmMoney"));
					var res;
					// if (this.type == "balance") {
					//   res = await cashApply({
					//     cash: this.inputNum,
					//     type: this.select_type,
					//     cash_type: 0
					//   });
					// } else {
					//   res = await this.$allrequest.shop.cashSubmitApply({
					//     cash: this.inputNum,
					//     type: this.select_type,
					//     cash_type: 0
					//   });
					// }
					
					console.log('提交数据',this.mchObj,this.inputNum,this.new)
					
					
					res = await this.$allrequest.teamCenter.postwithdrawa({
						cash: this.inputNum,
						type: this.new,
						name: this.mchObj.name,
						account: this.mchObj.account,
						bank: this.mchObj.bank || null,
					});
					this.getCashInfo();
					uni.showModal({
						title: "提示",
						content: "申请成功",
						showCancel: false,
						success: (result) => {
							if (result.confirm) {
								this.$utils.goBack();
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}, 1000);
			}
		},
		computed: {
			// 根据卡类型返回当前卡信息
			cardData() {
				return (type) => {
					let i = this.cardList.findIndex((item) => item.type == type);
					if (i == -1) return false;
					return this.cardList[i];
				};
			}
		},
		filters: {
			toString4(str) {
				return str.substr(str.length - 4);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.cash {
		color: #262626;
		font-family: PingFang SC;
		padding: 0 36rpx;
	}

	.way {
		height: 102rpx;
		border-bottom: 2rpx solid #f1f1f1;

		>view:nth-child(1) {
			height: 42rpx;
			font-size: 30rpx;
			font-weight: 600;
		}

		>view:nth-child(2) {
			height: 40rpx;
			font-size: 28rpx;

			.iconfont {
				font-size: 44rpx;

				&:nth-child(1) {
					margin-right: 10rpx;
				}
			}

			>text:nth-child(2) {
				margin-top: -2rpx;
			}
		}
	}

	.input-box {
		.input-title {
			padding: 30rpx 0;
			line-height: 42rpx;
			font-size: 30rpx;
			font-weight: 600;
		}

		.input {
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1px solid #f1f1f1;
			padding-bottom: 20rpx;

			>view:nth-child(1) {
				font-size: 40rpx;
				font-weight: 600;
				transform: translateY(8rpx);
			}

			>view:nth-child(2) {
				flex: 1;
				width: 0;

				/deep/.u-input__input {
					font-size: 56rpx;
					font-weight: 600;
					height: 112rpx;
					color: #262626;
				}
			}
		}
	}

	.all-withdrawal {
		margin-top: 28rpx;
		margin-bottom: 80rpx;
		height: 34rpx;
		font-size: 24rpx;
		color: #8c8c8c;
	}

	.btn {
		width: 678rpx;
		height: 88rpx;
		background: #f0250e;
		opacity: 1;
		border-radius: 120rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #ffffff;
	}

	.popup-box {
		width: 600rpx;
		padding: 0 50rpx;
		color: #262626;

		.title {
			height: 90rpx;
			line-height: 90rpx;
			font-size: 32rpx;
			font-weight: 600;
			text-align: center;
		}

		.popup-item {
			height: 100rpx;
			border-bottom: 1px solid #f1f1f1;
			font-size: 28rpx;

			.iconfont {
				font-size: 50rpx;
				margin-right: 15rpx;
			}
		}
	}
</style>